package com.central.dataManage.common.datasourcePlugin;

import com.central.common.model.DatasourceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Tindy
 * @date 2021/7/5
 * @describe produce datasourcePlugin in this custom defined datasource factory.
 */
public class DatasourcePluginFactory {
    private static final Logger logger = LoggerFactory.getLogger(DatasourcePluginFactory.class);

    public static BaseDatasourcePlugin getDatasourcePlugin(DatasourceInfo datasource) {
        try {
            switch (datasource.getDatasourceType()) {
                case MYSQL:
                    return new MysqlDatasourcePlugin(datasource);
                case HIVE:
                    return new HiveDatasourcePlugin(datasource);
                case ORACLE:
                    return new OracleDatasourcePlugin(datasource);
                case HDFS:
                    return new HdfsDatasourcePlugin(datasource);
                case KAFKA:
                    return new KafkaDatasourcePlugin(datasource);
                default:
                    return null;
            }
        } catch (Exception e) {
            logger.error("Get datasource object error", e);
            return null;
        }
    }
}
